package com.tjsinfo.tjsoa.mail.action;

import java.sql.ResultSet;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IJDBCDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;

/**
 * 根据邮件地址查询用户
 * @author wangwei
 *
 */
public class FindUserByEmailAction extends Action{
	private IJDBCDao jdbcdao;

	public IJDBCDao getJdbcdao() {
		return jdbcdao;
	}

	public void setJdbcdao(IJDBCDao jdbcdao) {
		this.jdbcdao = jdbcdao;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String emailInput = request.getParameter("emailInput");
		
		String sqlku = "";
		String sql = "";
		boolean bl = true;
		for (int i = 1; i <= 5; i++) {
			sqlku = ToolKit.getProperties("com/tjsinfo/tjsoa/mail/properties/systemResource.properties", this).getProperty(Integer.valueOf(i).toString());
			
			if (sqlku!=null && !"".equals(sqlku)) {
				sql = "select userId,userName from "+sqlku+".dbo.t_system_user where eMail='"+emailInput+"'";
				ResultSet rs = jdbcdao.executeQuary(sql);
				if (rs.next()) {
					int id = rs.getInt("userId");
					String username = rs.getString("userName");
					response.getWriter().print(Integer.valueOf(id)+","+username+","+i+"@");

					bl = false;
					break;
				}
			}
		}
		jdbcdao.closeRs();
		jdbcdao.closeStmt();
		jdbcdao.closeConn();
		if (bl) {
			response.getWriter().print("no");
		}
		
		return null;
	}
}
